<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="renderer" content="webkit"> 
	<meta content="always" name="referrer">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="css/layui.css">
    <link rel="stylesheet" href="css/login.css">
    <link rel="stylesheet" href="css/zhanghu.css">
    <script src="js/jquery.min.js"></script>
	<script src="lib/layui/layui.js"></script>
<script src="js/ajaxSet.js" type="text/javascript" charset="utf-8"></script>
    <style>
		#userName{
			float: left;
			width: 75px;
			text-align: center;
			position: relative;
			cursor: pointer;
			display: none;
		}
		#userName li:after{
			display:block;content:"";visibility:hidden;height:0;
			border-bottom:  1px solid #000000;
		}
		#userName dl{
			top: 42px;
			width: 100%;
			position: absolute;
			display: none;
			background: #fff;
			z-index: 9999;
		}
	</style>
	<style>
		.name{
			margin-top: 20px;
			font-size: 20px;
		}
		.address{
			margin-top: 30px;
			font-size: 20px;
		}
		.money{
			margin-top: 20px;
			font-size: 20px;
		}
		.info{
			color: #f00;
			font-size: 20px;
			margin-top: 30px;
		}
		#searchBtn{
		    background: #ff660c;
		    font-size: 24px;
		    color: #ffffff;
		    text-align: center;
		    width: 100px;
		    line-height: 42px;
		    border: none;
		    float: left;
		    cursor: pointer;
		}
	</style>
</head>
<body style="background: #f8f8f8;">
    <div class="header">
	<div class="w_1190">
		<div class="h_right fr">
			<a href="index.html">YIXA首页</a>
			<a href="dingdan.html">我的订单</a>
			<a href="zhanghu.html">账户设置</a>
			<a href="about.html">关于我们</a>
		</div>
		<div class="h_left">
			<ul id="userName">
				<li></li>
				<dl>
					<dd>退出登录</dd>
				</dl>
			</ul>
			<!-- 未登录 -->
				
				<a href="login.html" class="c_01afff" id="login">登录</a>
				<a href="register.html" class="registerno">免费注册</a>
			<!-- 已登录 -->
		</div>
	</div>
</div>
<script type="text/javascript">
	layui.use(['layer'], function() {
        var layer = layui.layer;
	
	$("#userName").on("click",function(){
	    $(this).find("dl").slideToggle(200)
	})
	
	$("#userName dd").on("click",function(){
	    $.ajax({
	    	type:"post",
	    	url:"http://52lvu.cn:8080/api/login/logout",
	        data:{
	            userId : token.userId
	        },success : function (result){

	            
	            if (result.resultCode == 200) {
	            	localStorage.removeItem("token");
	            	window.location.href="login.html"
	            }
	            
	        },error : function (e){
	           layer.msg("请求错误，请稍后重试",{icon:2,time:2000})
	        }
	    });
	})
	
	var token = JSON.parse(localStorage.getItem('token'));
	
	if (token) {
		var expiredTime = 1800000;
		var loginTime = token.loginTime
		var nowTime = new Date().getTime();

		
		if ( (nowTime - loginTime) > expiredTime ) {
			localStorage.removeItem("token");
			window.location.href = "login.html";
		}else{
			$("#userName").show(); 
			$(".registerno").hide();
			$("#login").hide()
			$("#userName li").html(token.userName)
		}
	}else{
	    window.location.href="login.html";
	}
})
</script>

    <div class="dingdan">
        <div class="title">酒店列表</div>
        <div class="search-bar clearfloat">
            <div class="search">
                <input type="text" placeholder="输入酒店名称进行查询" id="hotelName">
            </div>
            <div class="layui-inline" style="margin-left: 50px;">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="comedata" placeholder="yyyy-MM-dd">
                </div>
            </div>
            <div style="float: left;margin: 0 10px;line-height: 40px;font-size: 20px;">-</div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="leveldata" placeholder="yyyy-MM-dd">
                </div>
            </div>
            <button id="searchBtn">搜索</button>
        </div>
        <div class="list w-1200 clearfloat">
            <div class="caption">
                <a class="active">酒店列表</a>
            </div>
            <div class="main" style="min-height: 100px;">
                <div class="tab lift1" id="listCont">
					
                </div>
            </div>
            <div id="fyq" style="text-align: center;margin-top: 20px;"></div>
        </div>
    </div>

    <div id="footer"></div>
   
</body>
</html>



<script src="js/wang.js" type="text/javascript" charset="utf-8"></script>
<script>
layui.use(['laydate','laypage','laytpl'], function() {
   
    var laytpl = layui.laytpl ,
   	    laypage = layui.laypage ,
   	    laydate = layui.laydate ;
   	    
   	    $("#qq").load("lib/qq.html");
   	    $("#footer").load("lib/footer.html");
   	    laydate.render({
            elem: '#comedata',
            theme: '#ff660c'
        });
        
        laydate.render({
            elem: '#leveldata',
            theme: '#ff660c'
        });
   	   	
   	   	
   	   	if (wang.getQueryString("type") == 0 && wang.getQueryString("search") == null) {
	   		getHotHotel();
	   	}
	   	if (wang.getQueryString("type") == 1 && wang.getQueryString("search") == null){
	   		getHotel();
	   	}
	   	if (wang.getQueryString("search")!=null) {

	   		var searchList ={
   	    		name : wang.decodeURI(window.atob(wang.getQueryString("search"))),
   	    		startTime :"" ,	
   	    		endTime : "",
	    		start : 0,
	    		length : 8
   	    	}
	   		getList(searchList)
	   	}
   	   	
   	   	$("#searchBtn").on('click',function(){
   	    	var searchList ={
   	    		name : $("#hotelName").val(),
   	    		startTime : $("#comedata").val(),	
   	    		endTime : $("#leveldata").val(),
	    		start : 0,
	    		length : 8
   	    	}
   	    	getList(searchList)
   	   	})
   	   	
   	    function getList(searchList,curr){

			if (searchList) {
				var searchList = {
						name : searchList.name,
			    		startTime : searchList.startTime,
			    		endTime : searchList.endTime,
			    		start : curr || 0,
			    		length : 8
					}
			}else{
				var searchList =  {
					name : "",
		    		startTime : 0,
		    		endTime : 0,
		    		start : curr || 0,
		    		length : 8
				};
			}

		    $.ajax({
	    	    type:"post",
	    	    url:"http://52lvu.cn:8080/api/hotel/getList",
	    	    beforeSend: function(xhr) {
			        xhr.setRequestHeader("Content-Type", "application/json");
				},
	    	    data:JSON.stringify(searchList),
	    	    success : function (result){
	    	        
	    			if (result.resultCode!=200) {
	    				layer.msg("未查询到数据，请您更改搜索条件后重试",{icon:2,time:2000})
	    			} else{
						
						var data = result.data
						$("#listCont").empty();
						
						for(i = 0 ; i < data.length ; i++){
							var picList = data[i].picture.split(";")
							$("#listCont").append("<div class='clearfloat'><ul class='fl'><img src='http://52lvu.cn:8080/hotel/upload"+
								picList[0]+"' alt=''></ul><ul class='center'><li class='name'>"+
								data[i].name+"</li><li class='address'>"+
								data[i].address+"</li></ul><ul class='fr'><a href='info.html?hotelid="+
								data[i].hotelId+"&id="+
								data[i].id+"'><li class='info'>查看详情</li></a></ul></div>")
						}
						
						var pageNum = Math.ceil(result.ext/8)*10;

			            laypage.render({
			                elem: 'fyq', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
			                count: pageNum, //通过后台拿到的总页数
						    theme: '#ff660c',
			                curr: curr || 0, //当前页
			                jump: function(obj, first){ //触发分页后的回调
			                	obj.curr = (obj.curr-1)*8 ; 

			                    if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
			                        getList(searchList,obj.curr);
			                    }
			                }
			            });
	    			}
	    	    },error : function (e){
	    	        layer.msg("未查询到数据，请您更改搜索条件后重试",{icon:2,time:2000})
	    	    }
	    	});
		}
   	
   	function getHotHotel (){
   		var hotList = {
			name : ""
		}
   		$.ajax({
	        type:"post",
	        url:"http://52lvu.cn:8080/api/hotHotel/hotHotel",
			beforeSend: function(xhr) {
		        xhr.setRequestHeader("Content-Type", "application/json");
			},
			data : JSON.stringify(hotList),
	        success : function (result){
	        	
				if (result.resultCode!=200) {
    				layer.msg("未查询到数据，请您更改搜索条件后重试",{icon:2,time:2000})
    			} else{
						
					var data = result.data;
		            $(".caption a").html("推荐酒店")
		            console.log(data)
					$("#listCont").empty();
						
					for(i = 0 ; i < data.length ; i++){
						$("#listCont").append("<div class='clearfloat'><ul class='fl'><img src='http://52lvu.cn:8080/hotel/upload"+
							data[i].coverPic+"' alt=''></ul><ul class='center'><li class='name'>"+
							data[i].hotelName+"</li><li class='address'>"+
							data[i].address+"</li></ul><ul class='fr'><a href='info.html?hotelid="+
							data[i].hotelId+"&id="+
							data[i].id+"'><li class='info'>查看详情</li></a></ul></div>")
					}
						
					
    			}
    	    },error : function (e){
    	        layer.msg("未查询到数据，请您更改搜索条件后重试",{icon:2,time:2000})
    	    }
	        
	    });	
   	}
   	
   	
   	function getHotel(){
   	    $.ajax({
	        type:"post",
	        url:"http://52lvu.cn:8080/api/hotel/bannerHotel",
	        success : function (result){
	    		var data = result.data;

	            
	            if (result.resultCode!=200) {
	    				layer.msg("未查询到数据，请您更改搜索条件后重试",{icon:2,time:2000})
	    			} else{
//	    				window.location.href = "searchList.html?search="+window.btoa(wang.encodeURI(name))

						$("#listCont").empty();
						
						for(i = 0 ; i < data.length ; i++){
							var picList = data[i].pricture.split(";")
							
							$("#listCont").append("<div class='clearfloat'><ul class='fl'><img src='http://52lvu.cn:8080/hotel/upload"+
								picList[0]+"' alt=''></ul><ul class='center'><li class='name'>"+
								data[i].name+"</li><li class='address'>"+
								data[i].address+"</li></ul><ul class='fr'><a href='info.html?hotelid="+
								data[i].hotelId+"&id="+
								data[i].id+"'><li class='info'>查看详情</li></a></ul></div>")
						}
			            
	    			}
	            
	        },error : function (e){
	            layer.msg("请求错误！请稍候重试",{icon:2,time:3000});
	        }
	    });
   	}
   	
})
</script>